import axios from '../plugins/axios';

//服务 就是一个异步函数，返回 Promise

export const checkUserInput = async () => {
    //校验用户输入是否合法
    return true
};

export const queryLogin = async ({username,password}) => {

    // 携带数据 对象  字符  URLSearchParams
    let params = new URLSearchParams();
    params.append("username",username);
    params.append("password",password);


    if (checkUserInput(username,password)) {
        return axios({
            url:'/mock/login',
            method:'post',
            data: params//携带数据 对象  字符  URLSearchParams
        });
    }else{
        return false;//参数校验失败，返回失败原因
    }
};

export const queryReg = async ({username,password,icon}) => {

    let params = new URLSearchParams();
    params.append("username",username);
    params.append("password",password);

    // await checkUserInput(username,password,icon)
    //icon input:file
    if (icon.files.length>0){
        params.append("icon",icon.files[0]);
    }

    return axios({
        url:'/mock/reg',
        method:'post',
        data: params//携带数据 对象  字符  URLSearchParams
    });
};

export const queryLogout = async () => {
    return axios({
        url:'/mock/logout',
        method:'post',
    });
};